/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package io.iec.edp.caf.boot.starter.middleware.spi;

import io.iec.edp.caf.autoconfigure.spi.AutoConfigurationExclusion;
import io.iec.edp.caf.commons.runtime.CafEnvironment;

import java.util.ArrayList;
import java.util.List;

/**
 * Tomcat需要移除的自动配置类
 * @author wangyandong
 * @date 2021/09/13 19:10
 * @email wangyandong@inspur.com
 */
public class TomcatExclusion implements AutoConfigurationExclusion {
    /**
     * 返回需要排除的自动配置列表
     *
     * @return
     */
    @Override
    public List<String> exclude() {
        String middlewareName = System.getProperty("middleware.servlet", "none");
        if(middlewareName.equalsIgnoreCase("none"))
            middlewareName = CafEnvironment.getEnvironment().getProperty("server.container","tomcat");
        List<String> list = new ArrayList<>();
        boolean needExclude = !middlewareName.equalsIgnoreCase("tomcat");
        if(needExclude) {
            list.add("org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration");
            list.add("org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration");
            list.add("org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration");
            list.add("org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration");
            list.add("org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration");
            list.add("io.iec.edp.caf.boot.starter.middleware.config.TomcatAutoConfiguration");
        }
        return list;
    }
}
